namespace OnlineMediaAnalyzer.Migrations
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class init : DbMigration
    {
        public override void Up()
        {
            CreateTable(
                "dbo.Articles",
                c => new
                    {
                        ID = c.Int(nullable: false, identity: true),
                        Identification = c.String(nullable: false, maxLength: 256),
                        Title = c.String(nullable: false, maxLength: 256),
                        Description = c.String(maxLength: 1024),
                        Url = c.String(maxLength: 256),
                        Time = c.DateTime(nullable: false),
                        Author = c.String(nullable: false, maxLength: 64),
                        FetchingTime = c.DateTime(nullable: false),
                        FeedID = c.Int(nullable: false),
                        Sentiment = c.Int(),
                        Self = c.String(maxLength: 32),
                    })
                .PrimaryKey(t => t.ID)
                .ForeignKey("dbo.Feeds", t => t.FeedID, cascadeDelete: true)
                .Index(t => t.FeedID);
            
            CreateTable(
                "dbo.Categories",
                c => new
                    {
                        ID = c.Int(nullable: false, identity: true),
                        Name = c.String(nullable: false, maxLength: 64),
                        Url = c.String(maxLength: 128),
                        FeedID = c.Int(nullable: false),
                        Self = c.String(maxLength: 32),
                    })
                .PrimaryKey(t => t.ID)
                .ForeignKey("dbo.Feeds", t => t.FeedID, cascadeDelete: true)
                .Index(t => t.FeedID);
            
            CreateTable(
                "dbo.Feeds",
                c => new
                    {
                        ID = c.Int(nullable: false, identity: true),
                        Name = c.String(nullable: false, maxLength: 32),
                        Url = c.String(nullable: false, maxLength: 256),
                        ChannelID = c.Int(nullable: false),
                        RSSMapID = c.Int(nullable: false),
                        Self = c.String(),
                    })
                .PrimaryKey(t => t.ID)
                .ForeignKey("dbo.Channels", t => t.ChannelID, cascadeDelete: true)
                .ForeignKey("dbo.RSSMaps", t => t.RSSMapID, cascadeDelete: true)
                .Index(t => t.ChannelID)
                .Index(t => t.RSSMapID);
            
            CreateTable(
                "dbo.Channels",
                c => new
                    {
                        ID = c.Int(nullable: false, identity: true),
                        Name = c.String(nullable: false, maxLength: 32),
                        Url = c.String(nullable: false, maxLength: 128),
                        Self = c.String(maxLength: 32),
                    })
                .PrimaryKey(t => t.ID);
            
            CreateTable(
                "dbo.FeedParties",
                c => new
                    {
                        ID = c.Int(nullable: false, identity: true),
                        LastFetchTime = c.DateTime(nullable: false),
                        FeedID = c.Int(nullable: false),
                        PartyID = c.Int(nullable: false),
                        ArticlesCount = c.Int(nullable: false),
                        ArticlesMemberCount = c.Int(nullable: false),
                        PosArticlesCount = c.Int(nullable: false),
                        NegArticlesCount = c.Int(nullable: false),
                        Date = c.DateTime(nullable: false),
                    })
                .PrimaryKey(t => t.ID)
                .ForeignKey("dbo.Feeds", t => t.FeedID, cascadeDelete: true)
                .ForeignKey("dbo.Parties", t => t.PartyID, cascadeDelete: true)
                .Index(t => t.FeedID)
                .Index(t => t.PartyID);
            
            CreateTable(
                "dbo.Parties",
                c => new
                    {
                        ID = c.Int(nullable: false, identity: true),
                        Name = c.String(nullable: false, maxLength: 128),
                    })
                .PrimaryKey(t => t.ID);
            
            CreateTable(
                "dbo.PartyKeywords",
                c => new
                    {
                        ID = c.Int(nullable: false, identity: true),
                        PartyID = c.Int(nullable: false),
                        Keyword = c.String(nullable: false, maxLength: 128),
                    })
                .PrimaryKey(t => t.ID)
                .ForeignKey("dbo.Parties", t => t.PartyID, cascadeDelete: true)
                .Index(t => t.PartyID);
            
            CreateTable(
                "dbo.PartyMembers",
                c => new
                    {
                        ID = c.Int(nullable: false, identity: true),
                        Name = c.String(nullable: false, maxLength: 64),
                        PartyID = c.Int(nullable: false),
                    })
                .PrimaryKey(t => t.ID)
                .ForeignKey("dbo.Parties", t => t.PartyID, cascadeDelete: true)
                .Index(t => t.PartyID);
            
            CreateTable(
                "dbo.MemberMentions",
                c => new
                    {
                        ID = c.Int(nullable: false, identity: true),
                        PartyMemberID = c.Int(nullable: false),
                        FeedID = c.Int(nullable: false),
                        MentionsCount = c.Int(nullable: false),
                        PosMentionsCount = c.Int(nullable: false),
                        NegMentionsCount = c.Int(nullable: false),
                        Date = c.DateTime(nullable: false),
                    })
                .PrimaryKey(t => t.ID)
                .ForeignKey("dbo.Feeds", t => t.FeedID, cascadeDelete: true)
                .ForeignKey("dbo.PartyMembers", t => t.PartyMemberID, cascadeDelete: true)
                .Index(t => t.PartyMemberID)
                .Index(t => t.FeedID);
            
            CreateTable(
                "dbo.FeedStatistics",
                c => new
                    {
                        ID = c.Int(nullable: false, identity: true),
                        FeedID = c.Int(nullable: false),
                        ArticlesCount = c.Int(nullable: false),
                        PoliticalArticlesCount = c.Int(nullable: false),
                        MultiPartyArticlesCount = c.Int(nullable: false),
                        PartyMentionsCount = c.Int(nullable: false),
                        PosPoliticalArticlesCount = c.Int(nullable: false),
                        NegPoliticalArticlesCount = c.Int(nullable: false),
                        Date = c.DateTime(nullable: false),
                    })
                .PrimaryKey(t => t.ID)
                .ForeignKey("dbo.Feeds", t => t.FeedID, cascadeDelete: true)
                .Index(t => t.FeedID);
            
            CreateTable(
                "dbo.RSSMaps",
                c => new
                    {
                        ID = c.Int(nullable: false, identity: true),
                        Name = c.String(nullable: false, maxLength: 32),
                        ItemMapping = c.String(nullable: false, maxLength: 32),
                        TitleMapping = c.String(nullable: false, maxLength: 32),
                        GuidMapping = c.String(nullable: false, maxLength: 32),
                        UrlMapping = c.String(nullable: false, maxLength: 32),
                        DescriptionMapping = c.String(nullable: false, maxLength: 32),
                        AuthorMapping = c.String(nullable: false, maxLength: 32),
                        TimeMapping = c.String(nullable: false, maxLength: 32),
                        CategoryMapping = c.String(nullable: false, maxLength: 32),
                        Self = c.String(maxLength: 32),
                    })
                .PrimaryKey(t => t.ID);
            
            CreateTable(
                "dbo.ArticleCategories",
                c => new
                    {
                        ArticleID = c.Int(nullable: false),
                        CategoryID = c.Int(nullable: false),
                    })
                .PrimaryKey(t => new { t.ArticleID, t.CategoryID })
                .ForeignKey("dbo.Articles", t => t.ArticleID)
                .ForeignKey("dbo.Categories", t => t.CategoryID)
                .Index(t => t.ArticleID)
                .Index(t => t.CategoryID);
            
        }
        
        public override void Down()
        {
            DropForeignKey("dbo.ArticleCategories", "CategoryID", "dbo.Categories");
            DropForeignKey("dbo.ArticleCategories", "ArticleID", "dbo.Articles");
            DropForeignKey("dbo.Categories", "FeedID", "dbo.Feeds");
            DropForeignKey("dbo.Feeds", "RSSMapID", "dbo.RSSMaps");
            DropForeignKey("dbo.FeedStatistics", "FeedID", "dbo.Feeds");
            DropForeignKey("dbo.PartyMembers", "PartyID", "dbo.Parties");
            DropForeignKey("dbo.MemberMentions", "PartyMemberID", "dbo.PartyMembers");
            DropForeignKey("dbo.MemberMentions", "FeedID", "dbo.Feeds");
            DropForeignKey("dbo.PartyKeywords", "PartyID", "dbo.Parties");
            DropForeignKey("dbo.FeedParties", "PartyID", "dbo.Parties");
            DropForeignKey("dbo.FeedParties", "FeedID", "dbo.Feeds");
            DropForeignKey("dbo.Feeds", "ChannelID", "dbo.Channels");
            DropForeignKey("dbo.Articles", "FeedID", "dbo.Feeds");
            DropIndex("dbo.ArticleCategories", new[] { "CategoryID" });
            DropIndex("dbo.ArticleCategories", new[] { "ArticleID" });
            DropIndex("dbo.FeedStatistics", new[] { "FeedID" });
            DropIndex("dbo.MemberMentions", new[] { "FeedID" });
            DropIndex("dbo.MemberMentions", new[] { "PartyMemberID" });
            DropIndex("dbo.PartyMembers", new[] { "PartyID" });
            DropIndex("dbo.PartyKeywords", new[] { "PartyID" });
            DropIndex("dbo.FeedParties", new[] { "PartyID" });
            DropIndex("dbo.FeedParties", new[] { "FeedID" });
            DropIndex("dbo.Feeds", new[] { "RSSMapID" });
            DropIndex("dbo.Feeds", new[] { "ChannelID" });
            DropIndex("dbo.Categories", new[] { "FeedID" });
            DropIndex("dbo.Articles", new[] { "FeedID" });
            DropTable("dbo.ArticleCategories");
            DropTable("dbo.RSSMaps");
            DropTable("dbo.FeedStatistics");
            DropTable("dbo.MemberMentions");
            DropTable("dbo.PartyMembers");
            DropTable("dbo.PartyKeywords");
            DropTable("dbo.Parties");
            DropTable("dbo.FeedParties");
            DropTable("dbo.Channels");
            DropTable("dbo.Feeds");
            DropTable("dbo.Categories");
            DropTable("dbo.Articles");
        }
    }
}
